package com.jzd1997.lesson1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Scanner;

public class Lesson1 {
    private static Logger logger = LoggerFactory.getLogger(Lesson1.class);

    public static void main(String[] args) {
        try{
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入数字1");
            String input = "";
            input = scanner.nextLine();
            double operand1 = Double.parseDouble(input);
            System.out.println("请输入运算符");
            String operator = scanner.nextLine();
            System.out.println("请输入数字2");
            input = scanner.nextLine();
            double operand2 = Double.parseDouble(input);
            double result = 0;
            switch(operator){
                case "+":
                    result = operand1 + operand2;
                    break;
                case "-":
                    result = operand1 - operand2;
                    break;
                case "*":
                    result = operand1 * operand2;
                    break;
                case "/":
                    result = operand2==0?0:operand1/operand2;
                    break;
                default:
                    throw new Exception("错误的运算符");
            }
            System.out.printf("%.2f %s %.2f = %.2f",operand1,operator,operand2,result);
        }catch(Exception e){
            logger.error(e.getMessage(),e);
        }
    }
}
